<link rel="stylesheet" type="text/css" href="<{$env.app.res_url}>/style.css" media="screen" />
<form action="index.php?app=<{$env.get.app}>&ctl=<{$env.get.ctl}>&act=<{$act}>" method="post" id="order_frm" name="order_frm">
    <div id="gEditor-Body">
      <div class="spage-main-box">
          <div class="tableform">
          <div id="x-g-basic" class="goods-detail">
            <div class="edit_box">
              <table width="100%" border="0" cellspacing="0" cellpadding="0" class="gridlist">
              	<thead>
                <tr>
                  <th align="left">发票相关信息</th>
                </tr>
                </thead>
              </table>
            <div class="h_10px"></div>
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                  <td width="70" align="center" nowrap="nowrap"><strong>&nbsp;&nbsp;&nbsp;订单号：</strong></td>
                  <td><strong>&nbsp;<{$invoice_order.order_bn}></strong></td>
                  <td width="130" align="right"><strong>运费：</strong></td>
                  <td>&nbsp;&yen;<{$ome_orders.shipping.cost_shipping}></td>
              </tr>
              
              <tr>
                  <td align="center" nowrap="nowrap"><strong>订单总额：</strong></td>
                  <td>
                    <span class="red">&nbsp;&yen;<label id="total_amount"><{$ome_orders.total_amount}><label></span>
                  </td>
                  <td align="right"><strong>已支付金额：</strong></td>
                  <td>&nbsp;&yen;<{$ome_orders.payed}></td>
                </tr>
                <tr>
                  <td align="center" nowrap="nowrap"><strong>开票金额：</strong></td>
                  <td>
                    <span class="red">&nbsp;&yen;
                        <input size="10" <{if $invoice_order.mode == '1'}> style="display:none;"<{/if}> type="text" name="item[amount]" id="amount_input" value="<{$invoice_order.amount}>" />
                        <span <{if $invoice_order.mode == '0'}> style="display:none;"<{/if}> id="amount_span"><{$invoice_order.amount}></span>
                     </span>
                  </td>
                </tr>
                <tr>
                  <td align="center" nowrap="nowrap"><strong>开票方式：</strong></td>
                  <td>
                    <input type="radio" onclick="selectMode(this);" name="item[mode]" value="0" <{if $invoice_order.mode == '0'}> checked="checked"<{/if}>>纸质发票&nbsp;&nbsp;&nbsp;
                    <input type="radio" onclick="selectMode(this);" name="item[mode]" value="1" <{if $invoice_order.mode == '1' }>checked="checked"<{/if}>>电子发票
                  </td>
                </tr>
                <tr id="tr_type_id" <{if $invoice_order.mode == '1'}> style="display:none" <{/if}>>
                  <td align="center" nowrap="nowrap"><strong>纸质类型：</strong></td>
                  <td>
                    <span>
                        <input type="radio" name="item[type_id]" value="0" <{if $invoice_order.type_id == '0'}> checked="checked"<{/if}>>普通发票&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="item[type_id]" value="1" <{if $invoice_order.type_id == '1' }>checked="checked"<{/if}>>专业发票
                     </span>
                  </td>
                </tr>
                <tr>
                    <td align="center" nowrap="nowrap"><strong>发票内容：</strong></td>
                    <td>
                        <select name="item[content_id]" class="x-input-select inputstyle" type="select">
                            <{foreach from=$invoice_content item=val}>
                                <option value="<{$val.content_id}>" <{if $invoice_order.content_id == $val.content_id}>selected<{/if}> ><{$val.content_name}></option> 
                            <{/foreach}>
                        </select> 
                        <em><font color="red">*</font></em>
                    </td>
                    <td align="right"><strong>发票抬头：</strong></td>
                    <td><{input type="title" size="50" name="item[title]" value=$invoice_order.title}></td>
                </tr>
                <tr>
                  <td align="center" nowrap="nowrap"><strong>发票备注：</strong></td>
                  <td colspan="3"><{input type="textarea" name="item[remarks]" cols="78" rows="3" required='required' maxlength="255" value=$invoice_order.remarks}><br>
                    <span class="color_1">备注信息文字长度，请不要超过255字节</span></td>
                </tr>
              </table>
              
              
              <table width="100%" border="0" cellspacing="0" cellpadding="0" class="gridlist">
                <thead><tr><th>开票方信息</th></tr></thead>
              </table>
              <div class="h_10px"></div>
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
	                  <td width="100" align="right" nowrap="nowrap"><strong>名称：</strong></td>
                      <td><input size="40" id="payee_name" type="text" name="item[payee_name]" value="<{$invoice_order.payee_name}>"/></td>
                      <td><strong>税号：</strong></td>
                      <td><input size="40" id="tax_no" type="text" name="item[tax_no]" value="<{$invoice_order.tax_no}>"/></td>
                    </tr>
                    <tr>
	                  <td width="100" align="right" nowrap="nowrap"><strong>地址：</strong></td>
                      <td><input size="40" id="address" type="text" name="item[address]" value="<{$invoice_order.address}>"/></td>
                      <td><strong>电话：</strong></td>
                      <td><input size="40" id="telephone" type="text" name="item[telephone]" value="<{$invoice_order.telephone}>"/></td>
                    </tr>
                    <tr>
	                  <td width="100" align="right" nowrap="nowrap"><strong>开票人：</strong></td>
                      <td><input size="40" id="payee_operator" type="text" name="item[payee_operator]" value="<{$invoice_order.payee_operator}>"/></td>
                      <td><strong>税率：</strong></td>
                      <td><input maxlength='2' size="1" id="tax_rate"  type="text" name="item[tax_rate]" value="<{$invoice_order.tax_rate}>"/>&nbsp;请填写不大于100的数字 例：17% 就填写 17；</td>
                    </tr>
                    <tr>
                      <td width="100" align="right" nowrap="nowrap"><strong>开户银行：</strong></td>
                      <td><input size="40" id="bank" type="text" name="item[bank]" value="<{$invoice_order.bank}>"/></td>
                      <td><strong>银行账号：</strong></td>
                      <td><input size="40" id="bank_no" type="text" name="item[bank_no]" value="<{$invoice_order.bank_no}>"/></td>
                    </tr>
              </table>
            
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="gridlist">
            	<thead><tr><th>客户信息</th></tr></thead>
            </table>
            <div class="h_10px"></div>
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                  <td width="100" align="right" nowrap="nowrap"><strong>客户名称：</strong></td>
                  <td><{input type="title" size="30" name="item[tax_company]" maxlength="50" value=$invoice_order.tax_company}></td>
                  <td><strong>客户电话：</strong></td>
                  <td><{input type="title" size="30" name="item[ship_tel]" maxlength="30" value=$invoice_order.ship_tel}></td>
              </tr>
                <tr>
                  <td align="right" nowrap="nowrap"><strong>客户开户银行：</strong></td>
                  <td><{input type="title" size="30" name="item[ship_bank]" maxlength="30" required='required' value=$invoice_order.ship_bank}></td>
                  <td><strong>客户银行账号</strong></td>
                  <td><{input type="number" size="32" name="item[ship_bank_no]" maxlength="32" required='required' value=$invoice_order.ship_bank_no}></td>
              </tr>
                <tr>
                  <td align="right"><strong>客户税号：</strong></td>
                  <td colspan="3"><{input type="title" size="32" name="item[ship_tax]" maxlength="32" required='required' value=$invoice_order.ship_tax}></td>
                </tr>
                <tr>
                  <td align="right"><strong>收货地区：</strong></td>
                  <td colspan="3">&nbsp;<{input app=ectools class="x-input" type="region" name="item[ship_area]" value="{$invoice_order.ship_area}" }></td>
                </tr>
                <tr>
                  <td align="right"><strong>收货地址：</strong></td>
                  <td colspan="3"><{input type="title" size="60" name="item[ship_addr]" maxlength="100" required='required' value=$invoice_order.ship_addr}> <em><font color="red">&nbsp;&nbsp;*</font></em></td>
                </tr>
			  </table>
			  
			  <table>
			     <tr>
                    <td>&nbsp;
                      <{input type="hidden" name="item[id]" value=$invoice_order.id}>
                      <{input type="hidden" name="item[order_id]" value=$invoice_order.order_id}>
                    </td>
                     <td><div class="table-action text_left"><{if $invoice_order.id}><{button label="保存发票信息" type="button" id="btn_submit" name="btn_submit" }><{else}><{button label="添加新记录" type="button" id="btn_submit" name="btn_submit" }><{/if}></div></td>
                     <td>&nbsp;</td>
                     <td>&nbsp;</td>
                 </tr>
			  </table>
			  
            </div>
          </div>
          </div>
      </div>
    </div>
</form>
<style type="text/css">
.dialog .dialog-content-body { background:#fff; border:none; }
.dialog .tableform { background: none repeat scroll 0 0 #F8F8F8; border: 1px solid #D9D9D9; }
.gridlist thead th { height:27px; line-height:27px; padding-left:12px;  }
.edit_box { padding:10px 20px 5px 20px; }
.h_10px { clear:both; width:100%; height:10px; }
</style>
<script>

//纸质发票 电子发票 切换
function selectMode(obj){
	var mode = parseInt(obj.getAttribute("value"));
	if(mode == 1){
		//选择的电子发票
		$("amount_input").hide();
		//电子发票开票金额必须为订单总金额+税额
		var total_amount = parseFloat($("total_amount").getText()).toFixed(3);
		var tax_rate = $("tax_rate").getValue()/100;	
		var tax = parseFloat(total_amount*tax_rate).toFixed(3);
		var invoice_amount = parseFloat(total_amount)+parseFloat(tax);
		invoice_amount = parseFloat(invoice_amount).toFixed(3); //编辑页/新建发票信息页 暂时保留3位小数
		$("amount_span").setText(invoice_amount);
		$("amount_span").show();
		$("tr_type_id").hide();
	}
	if(mode == 0){
		//选择的纸质发票
		$("amount_span").hide();
        $("amount_input").show();
        $("tr_type_id").show();
	}
}

//表单验证
function submit_frm(){
	var _form = $('order_frm');
	var mode = parseInt(_form.getElement("input[name='item[mode]']:checked").getValue()); //开票方式
	var amount = parseInt($('amount_input').getValue()); //开票金额
	var title = _form.getElement("input[name='item[title]']").getValue(); //发票抬头 
	var payee_name = _form.getElement("input[name='item[payee_name]']").getValue(); //开票方名称
	var tax_no = _form.getElement("input[name='item[tax_no]']").getValue(); //开票方税号
	var address = _form.getElement("input[name='item[address]']").getValue(); //开票方地址
	var telephone = _form.getElement("input[name='item[telephone]']").getValue(); //开票方电话 
	var payee_operator = _form.getElement("input[name='item[payee_operator]']").getValue(); //开票人
	var tax_rate = _form.getElement("input[name='item[tax_rate]']").getValue(); //税率
	var bank = _form.getElement("input[name='item[bank]']").getValue(); //开票方开户银行
	var bank_no = _form.getElement("input[name='item[bank_no]']").getValue(); //开票方银行账号 
	
	if(mode == 0){
		//纸质发票
		if(!amount){
		    alert("请填写开票金额");
		    $('amount_input').focus();
		    return false;
		}
	}
	if(!title){
        alert("请填写发票抬头");
        _form.getElement("input[name='item[title]']").focus();
        return false;
    }
	if(!payee_name){
        alert("请填写开票方的名称");
        _form.getElement("input[name='item[payee_name]']").focus();
        return false;
    }
	if(!tax_no){
        alert("请填写开票方的税号");
        _form.getElement("input[name='item[tax_no]']").focus();
        return false;
    }
	if(!address){
        alert("请填写开票方的地址");
        _form.getElement("input[name='item[address]']").focus();
        return false;
    }
	if(!telephone){
        alert("请填写开票方的电话");
        _form.getElement("input[name='item[telephone]']").focus();
        return false;
    }
	if(!payee_operator){
        alert("请填写开票方的开票人");
        _form.getElement("input[name='item[payee_operator]']").focus();
        return false;
    }
	if(!tax_rate){
        alert("请填写开票方的税率");
        _form.getElement("input[name='item[tax_rate]']").focus();
        return false;
    }
	if(!bank){
        alert("请填写开票方的开户银行");
        _form.getElement("input[name='item[bank]']").focus();
        return false;
    }
	if(!bank_no){
        alert("请填写开票方的银行账号");
        _form.getElement("input[name='item[bank_no]']").focus();
        return false;
    }
	
	return true;
	
}

(function(){
	
	var _form = $('order_frm');
	var btn = $('btn_submit');
	var finder = finderGroup['<{$env.get.finder_id}>'];
	
	_form.store('target',{
		onSuccess:function(response){
			var hash_res_obj = JSON.decode(response);
			if (hash_res_obj.success != undefined && hash_res_obj.success != ""){
				try{
					var _dialogIns = btn.getParent('.dialog').retrieve('instance');
				}catch(e){}
				if(_dialogIns){
					_dialogIns.close();
					finder.refresh();
				}
			}
		}
	});
	
	btn.addEvent('click',function(){
		var flag = submit_frm();
		if(flag){
			_form.fireEvent('submit',{stop:$empty});	
		}
    });
	
})();

</script>